package  
{
	import flash.display.MovieClip;
	/**
	 * ...
	 * @author Seven Gae
	 */
	public class Bricks 
	{
		public var brickMap: Array;
		
		public function Bricks(brickMap: Array) 
		{
			this.brickMap = brickMap;
			
			drawBricks(brickMap);
		}
		
		private function drawBricks(brickMap: Array):void
		{
			for (var i: int = 0; i < brickMap.length; i++)
			{
				for (var j: int = 0; j < brickMap[0].length; j++)
				{
					switch(brickMap[i][j])
					{
						case 0:
							break;
							
						case 1:
							var brick: MovieClip = new Tijolo();
							brick.x = j * 60 + 50;
							brick.y = i * 60 + 110;
							Main.Self.screen.addChild(brick);
							brickMap[i][j] = brick;
							brick.gotoAndStop(Math.round((Math.random() * 7) + 1));
							break;
							
						case 2:
							var oldBrick: MovieClip = new TijoloAntigo();
							oldBrick.x = j * 60 + 50;
							oldBrick.y = i * 60 + 110;
							Main.Self.screen.addChild(oldBrick);
							oldBrick.gotoAndStop(Math.round((Math.random() * 22) + 1));
							brickMap[i][j] = oldBrick;
							break;
					}
				}
			}
		}
		
		
		public function destroy():void
		{
			for (var i: int = 0; i < brickMap.length; i++)
			{
				for (var j: int = 0; j < brickMap[0].length; j++)
				{
					if (brickMap[i][j] is MovieClip)
					{
						Main.Self.screen.removeChild(brickMap[i][j]);
					}
				}
			}
		}
		
	}

}